home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: Mike Girou <girou@parashift.com>
- Newsgroups: comp.lang.c++
- Subject: Re: PLEASE Help! :(
- Date: Sat, 09 Mar 1996 16:28:24 -0600
- Organization: Paradigm Shift, Inc.
- Message-ID: <31420608.6750@parashift.com>
- References: <4hsqre$4d7@deadbird.db.erau.edu>
- NNTP-Posting-Host: ix-dfw13-10.ix.netcom.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-NETCOM-Date: Sat Mar 09 2:28:56 PM PST 1996
- X-Mailer: Mozilla 2.0 (Win95; I)
-
- Hi,
-
- Dump out the data as you read it in and ask yourself how strings are
- delimited. This will get you started on the right track.
-
- Part of the educational process comes from struggling with things you
- don't understand, and learning how to figure things out without asking
- for inappropriate help. You are short-changing yourself if you don't
- learn how to learn. It's okay to ask for occasional clues, usually
- from fellow students or the instructor, but that's it.
-
- If you feel that it is proper to post to a newsgroup, post to the
- correct newsgroup. This is comp.lang.c++ for the c++ language, not
- the c language.
-
- We've all felt that same frustrations that you are feeling now, and
- I suspect we are all sympathetic to your call for help. But, please,
- for your own good, don't look for help with homework problems unless
- it is something really obscure or specialized. Then, ask your
- instructor and if he doesn't know the answer, he can post to the
- proper newsgroup for help.
-
- Mike
-
-
-
- Konrad Kochan wrote:
- >
- > Howdy.. I have a program to write, but I'm clueless... Now I could
- > give you a 100 excuses and blame the instructor (and I should cause
- > all of it would be true.. :)
- >
- > Anyways, I'm clueless.. can someone, a good samaritan (or someone just
- > bored..) help me out!
- >
- > Here is the program statement..
- >
- > Write a C program to sort, using any sorting method, a text file
- > named RECORDS.DAT, of unknown length, of records organized as follows:
- >
- > Field 1. Contains an integer.
- > Field 2. Contains a string of exactly 20 characters.
- > Field 3. Contains a float followed by a newline character.
- >
- > Example of file organization:
- >
- > 234 Numa Chaikin 33000.0
- >
- > 234 Numa Chaikin 33000.0
- > 75 advertisements 55.55
- > 901 Shepard 15255.5
- > 3 Brook 120050.0
- > 888 non-descriptive 0.0
- >
- > Sorting has to be done lexicographically, that is, by the second field
- > using alphabetical order. This means that:
- >
- > 1. Upper-case and lower-case letters should be treated identically.
- > For example, the right order for a part of the list above is:
- > 888 non-descriptive 0.0
- > 234 Numa Chaikin 33000.0
- >
- > 2. The only punctuation sign used in strings is a dash '-', which
- > should be ignored in sorting (but not removed from words).
- >
- > ~
- > ~
- > ~
- > ~
- >
- > And here is what I got so far.. which DOESN'T work (right or otherwise, I
- > can't even get the program to scan the right fields from the file.. :(
- >
- > #include <stdio.h>
- > #include <stdlib.h>
- > #include <string.h>
- >
- > /* Global Variable Definition */
- >
- > int IntArr[512][5];
- > char WordsArr1[512][10];
- > char WordsArr2[512][10];
- > float FloatArr[512][5];
- > char inbuff[80];
- > int index=0;
- >
- > /* Function declaration */
- >
- > void Welcome(void);
- > void Goodbye(void);
- >
- > main()
- > {
- >
- > main()
- > {
- > /* Next function opens a file, if the file is missing, it prints
- > an error message */
- >
- > int i;
- > FILE * fin, * fout;
- > if (!(fin = fopen("RECORDS.DAT", "r")))
- > {
- > printf("Something is wrong: Probably file missing.\n");
- > exit(1); /* Program exits here if file is missing. */
- > }
- > printf("\nInput File = RECORDS.DAT\n");
- > /* This function prints a Welcome message */
- >
- > /* Welcome(); */
- >
- > /* This function scans in the array */
- >
- > while (fgets(inbuff,80,fin) !=NULL)
- > {
- > sscanf(inbuff,"%d %s %s %4.2f", &IntArr[index],&WordsArr1[index],&WordsArr2[inde
- > x],&FloatArr[index]);
- >
- > {
- > sscanf(inbuff,"%d %s %s %4.2f", &IntArr[index],&WordsArr1[index],&WordsArr2[inde
- > x],&FloatArr[index]);
- > index++;
- > }
- >
- > /* Opens the output file */
- >
- > if (!(fout = fopen("test", "w")))
- > {
- > printf("Something is wrong: File might be write protected.\n");
- > exit(1); /* Program exits here if file can't be opened. */
- > }
- >
- > for (i=0; i<index; i++)
- > fprintf(fout, "%d %s %s %4.2f\n", IntArr[i], WordsArr1[i],WordsArr2[i],
- >
- > FloatArr[i]);
- >
- > /* Prints the sorted array to the screen */
- >
- > for (i=0; i<index; i++)
- > printf("Original array: %d %s %s %4.2f \n", IntArr[i],WordsArr1[i],
- >
- > for (i=0; i<index; i++)
- > printf("Original array: %d %s %s %4.2f \n", IntArr[i],WordsArr1[i],
- > WordsArr2[i],FloatArr[i]);
- > fclose(fin);
- > fclose(fout);
- > }
- >
- > ~
- > ~
- > ~
- > ~
- > ~
- > ~
- > ~
- > ~
- > ~
- > ~
- > ~
- > ~
- > ~
- > ~
- > ~
- >
- > If you can either give me hints, rewrite the above, or write a totaly
- > new program I would appreciate it.. I know its a lot to ask for (to do some-
- > one elses homework pretty much..) but I'm really clueless..
- >
- > Thank you in advance!
-
- --
- Mike Girou girou@parashift.com
-